package com.qf.usefull.datedemo;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 计算自己活了多少分钟
 */
public class Demo02 {

    public static void main(String[] args) throws ParseException {

        String born = "2000-01-01 00:00:00";

        // 如何把字符串 转换位 date对象
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date birthDay = simpleDateFormat.parse(born);

        long time = birthDay.getTime();

//        long now = System.currentTimeMillis();
        long now = new Date().getTime();

        long aliveTime = now - time;
        System.out.println(aliveTime);
        System.out.println(aliveTime / 1000 / 60 / 60 /24/365);

        Date date = new Date();
        System.out.println(date);
        System.out.println(simpleDateFormat.format(date));

    }

}
